YZYZ.Admin						= {};
YZYZ.Admin.Route 				= {};
YZYZ.Admin.Route.grid 			= null;
YZYZ.Admin.Route.store			= null;
YZYZ.Admin.Route.columnModel 	= null;
YZYZ.Admin.Route.routeGroupStore= null;//行程板块
YZYZ.Admin.Route.groupCB 		= null;
YZYZ.Admin.Route.addGroupCB 	= null;
YZYZ.Admin.Route.searchName 	= null;//搜索的行程名字
YZYZ.Admin.Route.searchGroupCB  = null;//搜索的行程分组

YZYZ.Admin.Route.submitSearch = function(){
	YZYZ.Admin.Route.grid.getStore().setBaseParam('routeName', Ext.getCmp("searchName").getValue());
	YZYZ.Admin.Route.grid.getStore().setBaseParam('groupId', Ext.getCmp("searchRouteGroup").getValue());
	YZYZ.Admin.Route.grid.getStore().load({params :{start:0,limit:15}});
};
YZYZ.Admin.Route.opRender = function(value, metaData, record, rowIndex, colIndex, store){
	var html = "<div class='btnCotainer'>"
	if(value == false) {
		html = html + "<div class='divBtn' ><button type='button' onclick='YZYZ.Admin.Route.enableConfirm("+record.get('id')+")' class='btnDisabled divDisabled'>激活ֹ</button></div>"
	} else {
		html = html + "<div class='divBtn' ><button type='button' onclick='YZYZ.Admin.Route.disableConfirm("+record.get('id')+")' class='btnDisabled divEnabled'>禁止ֹ</button></div>"
	}
	html = html + "<div class='divBtn' ><button type='button' onclick='YZYZ.Admin.Route.showEditWin()' class='btnEdit'>编辑</button></div>";
	html = html + "<div class='divBtn' ><button type='button' onclick='YZYZ.Admin.Route.showRelatedWin()' class='btnEdit'>景区</button></div>";
	html = html + "<div class='divBtn'><button type='button' class='btnEdit' onclick='YZYZ.Admin.Route.confirm("+record.get('id')+")'>删除</button></div>";
	html = html + "</div>"
	return html;
};
YZYZ.Admin.Route.renderRouteGroup = function(value, metaData, record, rowIndex, colIndex, store){
	var count = YZYZ.Admin.Route.routeGroupStore.getCount();
	for(var i = 0; i < count; i ++){
		var rec = YZYZ.Admin.Route.routeGroupStore.getAt(i);
		if(parseInt(rec.get("id")) == parseInt(value)){
			return rec.get("name");
		}
	}
};

YZYZ.Admin.Route.init = function(){
	YZYZ.Admin.Route.searchName = new Ext.form.TextField({
		width:300,
		id:'searchName',
		fieldLabel:'行程名',
		renderTo:'divSearchName'
	});
	YZYZ.Admin.Route.routeGroupStore= new Ext.data.Store({  
			proxy: new Ext.data.HttpProxy ({
	            url: document.getElementById("getRouteGroupUrl").value
	        }),
	        reader: new Ext.data.JsonReader({
	        	root			: "data",
	        	totalProperty	: "sum"
        	}, [
                {name:'id',type:'int'},
                {name:'name'},
                {name:'routeGroupId'}
            ]),
	        remoteSort: false
		});
	YZYZ.Admin.Route.routeGroupStore.load({params:{start:0, limit:1000}});
	YZYZ.Admin.Route.groupCB = new Ext.form.ComboBox({  
	         id: 'editRouteGroup', 
	         name:'editRouteGroup', 
	         allowBlank: false,  
	         fieldLabel: "行程板块",  
	         hiddenName: 'hidRouteRegion',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.Admin.Route.routeGroupStore,  
	         mode: 'local',
	         width:300 ,
	         editable:false
 		});
 	YZYZ.Admin.Route.addGroupCB=new Ext.form.ComboBox({  
	         id: 'addRouteGroup', 
	         name:'addRouteGroup', 
	         allowBlank: false,  
	         fieldLabel: "行程板块",  
	         hiddenName: 'hidAddRoute',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.Admin.Route.routeGroupStore,  
	         mode: 'local',
	         width:300 ,
	         editable:false
 		});
 	YZYZ.Admin.Route.searchGroupCB = new Ext.form.ComboBox({  
	         id: 'searchRouteGroup', 
	         name:'searchRouteGroup', 
	         allowBlank: false,  
	         fieldLabel: "行程板块",  
	         hiddenName: 'groupId',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.Admin.Route.routeGroupStore,  
	         mode: 'local',
	         width:300 ,
	         editable:false,
	         renderTo:'divSearchGroup'
 		});
	YZYZ.Admin.Route.columnModel = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
            {header: '名称', width: 300, sortable: false, hideable:false, dataIndex: 'name'},
            {header: '所属分组', width: 150, sortable: false, hideable:false, dataIndex: 'routeGroupId', renderer:YZYZ.Admin.Route.renderRouteGroup},
            {header: '价格', width: 100, sortable: false, hideable:true, dataIndex: 'price'},
            {header: '显示级别', width: 100, sortable: false, hideable:false, dataIndex: 'level'},
            {header: '操作',id:'operations', width: 250, sortable: false, hideable:false, dataIndex: 'available', renderer:YZYZ.Admin.Route.opRender}
    	]);
	YZYZ.Admin.Route.store = new Ext.data.Store({  
			proxy: new Ext.data.HttpProxy ({
	            url: document.getElementById("getRouteUrl").value
	        }),
	        reader: new Ext.data.JsonReader({
	        	root			: "data",
	        	totalProperty	: "sum"
        	}, [
                {name:'id'},
                {name:'name'},
                {name:'price'},
                {name:'level', type:'int'},
                {name:'available',type:'boolean'},
                {name:'contents'},
                {name:'routeGroupId', type:'int'}
            ]),
	        remoteSort: false
		});
	YZYZ.Admin.Route.grid = new Ext.grid.GridPanel({
			id			: "routeGrid",
			store		: YZYZ.Admin.Route.store,
			cm			: YZYZ.Admin.Route.columnModel,
			sm			: new Ext.grid.RowSelectionModel(),
			region		: 'center',
			height		: Ext.getBody().getHeight()-100,
			width		: Ext.getBody().getWidth(),
			viewConfig	: { forceFit:true },
			autoExpandColumn : 'operations',
			loadMask	: { msg:"数据加载中....." },
			bbar		: new Ext.PagingToolbar({   
				pageSize	: 15,   
				store		: YZYZ.Admin.Route.store,   
				displayInfo	: true,   
				displayMsg	: "第{0}条到{1}条  共{2}条",   
				emptyMsg	: "没有行程",
				items		:[{text:'添加行程',handler:YZYZ.Admin.Route.addNewRoute }]
			})              
		});
	YZYZ.Admin.Route.grid.on("dblclick",YZYZ.Admin.Route.showEditWin);
		 
	new Ext.Viewport({
		layout: 'border',
		items:[{
			region			: 'north',
			contentEl 		: 'divNorth',
			autoScroll		: false,
			layout			: 'fit',
			height 			: 100,
			layout 			: 'fit' 
		},{
			region			: 'center',
			cls				: 'divGrid',
			items 			: [YZYZ.Admin.Route.grid],
			autoScroll		: false,
			layout			: 'fit' 
		}]
	});
	YZYZ.Admin.Route.grid.getStore().load({params :{start:0,limit:15}});
};
Ext.onReady(YZYZ.Admin.Route.init,document);